/**
 * Created by Administrator on 2017/3/2.
 */
var pool = require('./DBConnectPool');

/**
 * 影院片库 筛选条件更新
 * 获取 影片：导演 演员 类型 年代
 * @param callBack
 */
module.exports =  {
    /**
     * 获得所有 影片类型（标签）
     * @param callBack
     */
    getMovieType :function (callBack){

    pool.getPoolConnection('mtsc', function (err, connection) {

        if (err) {
            console.log('get connection from pool failed in getMovieType: ', err);
            return;
        }

        var sql = 'SELECT m_y.movie_type from movie_type as m_y WHERE m_y.isdeleted = 0 ORDER BY hot_flag DESC';

        connection.query(sql, function (queryErr, result) {

            if (queryErr) {
                console.log('查询movie_type error: ', err);
                callBack({
                    isSuccess: false
                });
            } else {
                callBack({
                    isSuccess: true,
                    rows: result
                })
            }

            connection.release();
        });

    })

    },
    /**
     * 获得所有 影片 演员
     * @param callBack
     */
    getMovieActor :function (callBack){

        pool.getPoolConnection('mtsc', function (err, connection) {

            if (err) {
                console.log('get connection from pool failed in getMovieActor: ', err);
                return;
            }

            var sql = 'SELECT m_a.movie_actor from movie_actor as m_a WHERE m_a.isdeleted = 0 ORDER BY m_a.hot_flag DESC';

            connection.query(sql, function (queryErr, result) {

                if (queryErr) {
                    console.log('movie_actor error: ', err);
                    callBack({
                        isSuccess: false
                    });
                } else {
                    callBack({
                        isSuccess: true,
                        rows: result
                    })
                }

                connection.release();
            });

        })

    },
    /**
     * 获得所有 影片 出品地区
     * @param callBack
     */
    getMovieCountry :function (callBack){

        pool.getPoolConnection('mtsc', function (err, connection) {

            if (err) {
                console.log('get connection from pool failed in getMovieCountry: ', err);
                return;
            }

            var sql = 'SELECT m_c.movie_country from movie_country as m_c WHERE m_c.isdeleted = 0 ORDER BY m_c.hot_flag DESC';

            connection.query(sql, function (queryErr, result) {

                if (queryErr) {
                    console.log('查询movie_country error: ', err);
                    callBack({
                        isSuccess: false
                    });
                } else {
                    callBack({
                        isSuccess: true,
                        rows: result
                    })
                }

                connection.release();
            });

        })

    },
    /**
     * 获得所有 影片 导演
     * @param callBack
     */
    getMovieDirector :function (callBack){

        pool.getPoolConnection('mtsc', function (err, connection) {

            if (err) {
                console.log('get connection from pool failed in getMovieDirector: ', err);
                return;
            }

            var sql = 'SELECT m_d.movie_director from movie_director as m_d WHERE m_c.isdeleted = 0 ORDER BY m_d.hot_flag DESC';

            connection.query(sql, function (queryErr, result) {

                if (queryErr) {
                    console.log('查询movie_director error: ', err);
                    callBack({
                        isSuccess: false
                    });
                } else {
                    callBack({
                        isSuccess: true,
                        rows: result
                    })
                }

                connection.release();
            });

        })

    }
};
